package com.me.waterphase;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.me.waterphase.utils.Conversion;
import com.me.waterphase.utils.PhysicManager;


public class WaterImmobileObject {
		
	private float width;
	private float height;
	
	private String spriteName;
	
	private Body myBody;
	private WaterSprite sprite;
	
	public Vector2 getPosition(){
		return myBody.getPosition();
	}

	public float getWidth(){
		return width;		
	}
	
	public float getHeight(){
		return height;
	}
	
	public void setWidth(float _width){
		width = _width;
	}
	
	public void  setHeight(float _height){
		height = _height;
	}
	
	public String getspriteName(){
		return spriteName;
	}
	
	public WaterImmobileObject(String _spriteName, float _x, float _y, float _width, float _height){
		sprite = new WaterSprite(_spriteName, _width, _height);
		
		spriteName = _spriteName;
		width = _width;
		height = _height;
		
		//TODO - Stretch with the width and the height.
		
		myBody = PhysicManager.createRectBody(BodyType.StaticBody, _x, _y, 0f, 0f, 0f, _width, _height,false, false, true, false);
	}
	
	public WaterImmobileObject(String _spriteName, float _x, float _y, float _radius){
		sprite = new WaterSprite(_spriteName, _radius*2, _radius*2);
		
		width = _radius*2;
		height = _radius*2;
		
		//TODO - Stretch with the width and the height.
		
		myBody = PhysicManager.createCircleBody(BodyType.StaticBody, _x, _y, 0f, 0f, 0f, _radius, false, true);
	}
	
	public WaterImmobileObject(String _spriteName, float _x, float _y, float _width, float _height, Vector2[] _vectors){
		
		Vector2 widthAndHeight = PhysicManager.findVectorsWidthHeight(_vectors);
		
		
		sprite = new WaterSprite(_spriteName, widthAndHeight.x, widthAndHeight.y);
		
		//Set the bounds around the shape.
		width = widthAndHeight.x;
		height = widthAndHeight.y;
		
		//TODO - Stretch with the width and the height.
		
		myBody = PhysicManager.createPolyBody(BodyType.StaticBody, _x, _y, 0f,0f, 0f, _vectors, true);
	}
	
	
	public void render(){		
		
		float posX = Conversion.boxToWorld(myBody.getPosition().x)-(width*0.5f);
		float posY = Conversion.boxToWorld(myBody.getPosition().y)-(height*0.5f);
		
		sprite.render(posX, posY);
	}
	
	public void dispose()
	{
		sprite.dispose();
	}
}
